package com.chengqs.leetcode.utils;

public class TimeCostUtil {
    public interface Executor {
        void execute();
    }

    public static void timeCost(String methodName, Executor executor) {
        long start = System.currentTimeMillis();
        executor.execute();
        long end = System.currentTimeMillis();
        System.out.printf("方法 %s 执行耗时: %d ms%n", methodName, end - start);
    }

    public static void timeCost(Executor executor) {
        long start = System.currentTimeMillis();
        executor.execute();
        long end = System.currentTimeMillis();
        System.out.printf("方法执行耗时: %d ms%n", end - start);
    }
}
